home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 12 code / Components / Sources / MathComponent.c < prev    next >
Encoding:
Text File  |  1994-12-02  |  5.8 KB  |  208 lines  |  [TEXT/MMCC]

  1. /************************************************************************************
  2.  
  3.     File:        MathComponent.c
  4.  
  5.     Contains:    Math component routines.
  6.  
  7.     Written by:    Gary Woodcock
  8.  
  9.     Copyright:    © 1992 by Apple Computer, Inc.
  10.  
  11.     Change History (most recent first):
  12.  
  13.             
  14.     Project settings for 68K
  15.         Code model:                 Small, Smart or Large
  16.         Link Single Segment:        on (VERY important)
  17.         Project type:                Code Resource
  18.         File name:                    Math_Component
  19.         Sym name:                    Math_Component.SYM (not generated)
  20.         Resource name:                Math Component
  21.         Header type:                Standard
  22.         Multi Segment:                 on or off
  23.         ResType:                    _68K
  24.         ID:                            128 
  25.         SegType                        blank (unused since we are linking single segment)
  26.         Creator:                    gwck
  27.         File type:                    thng
  28.         Resource flags:                SysHeap
  29.         Project setup:
  30.             Segment 1 (Main Segment): MathComponent.c
  31.             Segment 2 (Group2): MacOS.lib, FatMathComponent.rsrc (See warning below)
  32.             Segment 3 (Group3): and MathComponentCommon.c
  33.             
  34.     Project settings for PPC 
  35.         Project type:                Code Resource
  36.         File name:                    Math_Component
  37.         Sym name:                    Math_Component.SYM (not generated)
  38.         Resource name:                Math Component
  39.         Header type:                None (VERY important)
  40.         ResType:                    _PPc
  41.         ID:                            128 
  42.         Creator:                    gwck
  43.         File type:                    thng
  44.         Resource flags:                SysHeap
  45.         Merge To File                on
  46.         Expand Uninitialized Data:     on
  47.         Main Entry Point            MainRD (VERY important)
  48.         Project setup:
  49.             Group 1 (Main Group): MathComponent.c
  50.             Group 2 (Group2): InterfaceLib, MathLib, ToolsLib.o
  51.             Group 3 (Group3): MathComponentCommon.c
  52.     
  53.     ***Warning*** FatMathComponent.rsrc has an extended thng resource which 
  54.     is set to require both PPC and 68K code.  If you want to test the 68K 
  55.     component by itself, use MathComponent.rsrc, instead.
  56.                         
  57.     CW components need to have the Link Single Segment switch checked.  The Multi-
  58.     segment switch can be checked or unchecked as fits your needs.  (Please 
  59.     see the User Guide for which situations require the Multi-segment switch.)
  60.     Putting everything into one segment eliminates segment loader errors that 
  61.     would occur if the startup code tried to call GetResource before 
  62.     OpenComponentResFile is called.  Components written in C are moveable, components 
  63.     written in C++ with virtual functions probably aren't.  Please see the 
  64.     C++ XCMD example on the CD for an example of how to deal C++ code resources.
  65.  
  66.     Project settings, port to PPC and comments by
  67.     Mark Anderson
  68.     metrowerks
  69.     12/1/94
  70.     
  71. ************************************************************************************/
  72.  
  73. //-----------------------------------------------------------------------
  74. // includes
  75.  
  76. #include "MathComponent.h"
  77. #include "MathComponentPrivate.h"
  78. #include "MathComponentCommon.h"
  79. #include <Errors.h>
  80. #ifndef powerc
  81.     #include <A4Stuff.h>
  82. #endif
  83.  
  84.  
  85. //-----------------------------------------------------------------------
  86. // Prototype (can't be in header or there is a conflict with Component Tester)
  87. #ifndef DEBUG_IT
  88.     pascal    ComponentResult    main    (ComponentParameters    *params,
  89.                                  Handle                    storage);
  90. #endif
  91.  
  92. //-----------------------------------------------------------------------
  93. //PPC Globals
  94. #ifdef powerc
  95.  
  96.     INSTANTIATE_ROUTINE_DESCRIPTOR(MathCanDo);
  97.     INSTANTIATE_ROUTINE_DESCRIPTOR(MathOpen);
  98.     INSTANTIATE_ROUTINE_DESCRIPTOR(MathClose);
  99.     INSTANTIATE_ROUTINE_DESCRIPTOR(MathVersion);
  100.     INSTANTIATE_ROUTINE_DESCRIPTOR(MathTarget);
  101.     INSTANTIATE_ROUTINE_DESCRIPTOR(MathDoDivide);
  102.     INSTANTIATE_ROUTINE_DESCRIPTOR(MathDoMultiply);
  103.  
  104. #ifndef DEBUG_IT
  105.     RoutineDescriptor MainRD = BUILD_ROUTINE_DESCRIPTOR(uppComponentRoutineProcInfo, main);
  106.     ProcInfoType __procinfo = uppComponentRoutineProcInfo;
  107. #endif
  108. #endif
  109.  
  110. //-----------------------------------------------------------------------
  111. #ifdef DEBUG_IT
  112.  
  113. // Use this declaration when we're running linked (for debugging)
  114. pascal    ComponentResult    MathDispatcher    (ComponentParameters    *params,
  115.                                          Handle                    storage)
  116.                                              
  117. #else
  118.  
  119. // Use this declaration when we're a standalone component
  120. pascal    ComponentResult    main    (ComponentParameters    *params,
  121.                                  Handle                    storage)
  122.  
  123. #endif DEBUG_IT
  124.  
  125. {
  126.     // This routine is the main dispatcher for the Math component
  127.     
  128.     ComponentResult    result = noErr;
  129.  
  130. #if !defined(powerc) && !defined(DEBUG_IT)
  131.     long             oldA4;
  132.     
  133.     oldA4 = SetCurrentA4();
  134. #endif
  135.  
  136.     // Did we get a Component Manager request code (< 0)?
  137.     if (params->what < 0)
  138.     {
  139.         switch (params->what)
  140.         {
  141.             case kComponentOpenSelect:        // Open request
  142.             {
  143.                 result = CallComponentFunctionUniv(params, MathOpen);
  144.                 break;
  145.             }    
  146.             case kComponentCloseSelect:        // Close request
  147.             {
  148.                 //if open fails, close gets called (why I don't know) so 
  149.                 //globals aren't allocated
  150.                 if (!storage)
  151.                     return result;
  152.                 result = CallComponentFunctionWithStorageUniv(storage, params, MathClose);
  153.                 break;    
  154.             }        
  155.             case kComponentCanDoSelect:        // Can Do request
  156.             {
  157.                 result = CallComponentFunctionUniv(params, MathCanDo);
  158.                 break;    
  159.             }
  160.             case kComponentVersionSelect:    // Version request
  161.             {
  162.                 result = CallComponentFunctionUniv(params, MathVersion);
  163.                 break;    
  164.             }    
  165.             case kComponentTargetSelect:    // Target request
  166.             {
  167.                 result = CallComponentFunctionWithStorageUniv(storage, params, MathTarget);
  168.                 break;    
  169.             }
  170.             case kComponentRegisterSelect:    // Register request not supported
  171.             default:                        // Unknown request
  172.             {
  173.                 result = paramErr;
  174.                 break;
  175.             }
  176.         }
  177.     }
  178.     else    // Was it one of our request codes?
  179.     {
  180.         switch (params->what)
  181.         {
  182.             case kDoDivideSelect:            // Divide request
  183.             {
  184.                 result = CallComponentFunctionUniv(params, MathDoDivide);
  185.                 break;    
  186.             }    
  187.             case kDoMultiplySelect:            // Multiply request
  188.             {
  189.                 result = CallComponentFunctionUniv(params, MathDoMultiply);
  190.                 break;    
  191.             }
  192.             
  193.             default:                        // Unknown request
  194.             {
  195.                 result = paramErr;
  196.                 break;
  197.             }
  198.         }
  199.     }
  200.  
  201. #if !defined(powerc) && !defined(DEBUG_IT)
  202.     SetA4(oldA4);
  203. #endif
  204.  
  205.     return (result);
  206. }
  207.                                              
  208.